package info.emm.weiyipro.demo;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import static android.content.pm.PackageManager.PERMISSION_GRANTED;

public class MainActivity extends AppCompatActivity {

    private EditText userEdt;
    private EditText roomEdt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        roomEdt = findViewById(R.id.roomEdt);
        userEdt = findViewById(R.id.userEdt);

        roomEdt.setText("5e3382ab705a8d4c6481cd6b");
        userEdt.setText("4841D92D2770D5FB22E8F06F45FC4E4C");
        View join = findViewById(R.id.join);
        join.setOnClickListener(v -> requestPermission());
    }

    private static final int WY_REQUEST_CODE = 100;

    private void requestPermission() {
        String[] permissions = new String[]{Manifest.permission.CAMERA,
                Manifest.permission.RECORD_AUDIO,
                Manifest.permission.READ_EXTERNAL_STORAGE,
                Manifest.permission.READ_PHONE_STATE,
                Manifest.permission.MODIFY_AUDIO_SETTINGS,
                Manifest.permission.READ_EXTERNAL_STORAGE};

        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(MainActivity.this,
                    permission) != PERMISSION_GRANTED) {
                ActivityCompat.requestPermissions(MainActivity.this,
                        permissions,
                        WY_REQUEST_CODE);
                return;
            }
        }
        ActivityMeeting.startEnter(MainActivity.this, userEdt.getText().toString().trim(), roomEdt.getText().toString().trim());//自定义界面
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                           int[] grantResults) {
        if (requestCode == WY_REQUEST_CODE
                && grantResults.length == 6
                && grantResults[0] == PERMISSION_GRANTED
                && grantResults[1] == PERMISSION_GRANTED
                && grantResults[2] == PERMISSION_GRANTED
                && grantResults[3] == PERMISSION_GRANTED
                && grantResults[4] == PERMISSION_GRANTED
                && grantResults[5] == PERMISSION_GRANTED) {

            ActivityMeeting.startEnter(MainActivity.this, userEdt.getText().toString().trim(), roomEdt.getText().toString().trim());
//            WySdk.getInstance().joinMeeting(MainActivity.this, "13123", "微议测试", serial);//带界面
        }
    }
}
